/**
 *    @file       netdef.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       2014年01月18日 23时08分57秒
 *
 *    @author     Theophilus (), wangtf418@gmail.com
 */
#ifndef _BF_NETDEF_H_
#define _BF_NETDEF_H_
#include "comdef.h"

#define BF_HTTP_VERSION_1_0 "HTTP/1.0"
#define BF_HTTP_VERSION_1_1 "HTTP/1.1"

static const bf_uint8_t BF_URL_ENCODE_MAP[] = 
{
//	0	1	2	3	4	5	6	7	8	9	10	11	12	13	14	15
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	//0-15
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	//16-31
	0,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	0,	0,	1,	//32-47
	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	1,	1,	1,	1,	1,	1,	//48-63
	1,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	//64-79
	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	1,	1,	1,	1,	0,	//80-95
	1,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	//96-111
	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	0,	1,	1,	1,	1,	1,	//112-127
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	//128-143
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	//144-159
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	//160-175
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	//176-191
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	//192-207
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	//208-223
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	//224-239
	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1,	1	//240-255
};

#define BF_HTTP_STATUS_TYPE 4
#define BF_HTTP_STATUS_SUB_TYPE 17

//effective buf not safe
#define BF_CHECK_HTTP_STATUSCODE(status_code) (status_code < 200 || status_code >= 600)? false:((status_code % 100 >= BF_HTTP_STATUS_SUB_TYPE)? false:true)
#define BF_GET_HTTP_STATUSSTR(status_code) ((BF_CHECK_HTTP_STATUSCODE(status_code))? (BF_HTTP_STATUS_STR[(status_code) / 100 - 2][(status_code) % 100]):NULL)

static const char * const BF_HTTP_STATUS_STR[BF_HTTP_STATUS_TYPE][BF_HTTP_STATUS_SUB_TYPE] = 
{
	{
		"200 OK",								//0
		"201 Created",							//1
		"202 Accepted",							//2
		NULL,									//3, NULL
		"204 No Content",						//4
		NULL,									//5, NULL
		"206 Partial Content"					//6,
	},

	{
		NULL,									//0, NULL
		"301 Moved Permanently",				//1
		"302 Moved Temporarily",				//2
		"303 See Other",						//3
		"304 Not Modified",						//4
		NULL,									//5, NULL
		NULL,									//6, NULL
		"307 Temporary Redirect",				//7
	},

	{
		"400 Bad Request",						//0
		"401 Unauthorized",						//1
		"402 Payment Required",					//2
		"403 Forbidden",						//3
		"404 Not Found",						//4
		"405 Not Allowed",						//5
		"406 Not Acceptable",					//6
		NULL,									//7, NULL
		"408 Request Time-out",					//8
		"409 Conflict",							//9
		"410 Gone",								//10
		"411 Length Required",					//11
		"412 Precondition Failed",				//12
		"413 Request Entity Too Large",			//13
		NULL,									//14, NULL
		"415 Unsupported Media Type",			//15
		"416 Requested Range Not Satisfiable",	//16
	},

	{
		"500 Internal Server Error",			//0
		"501 Not Implemented",					//1
		"502 Bad Gateway",						//2
		"503 Service Temporarily Unavailable",	//3
		"504 Gateway Time-out",					//4
		NULL,									//5, NULL
		NULL,									//6, NULL
		"507 Insufficient Storage"				//7
	}
};

enum bf_http_status_code_t
{
	BF_HTTP_STATUS_CODE_200 = 200,
	BF_HTTP_STATUS_CODE_201 = 201,
	BF_HTTP_STATUS_CODE_202 = 202,
	BF_HTTP_STATUS_CODE_204 = 204,
	BF_HTTP_STATUS_CODE_206 = 206,
	BF_HTTP_STATUS_CODE_301 = 301,
	BF_HTTP_STATUS_CODE_302 = 302,
	BF_HTTP_STATUS_CODE_303 = 303,
	BF_HTTP_STATUS_CODE_304 = 304,
	BF_HTTP_STATUS_CODE_307 = 307,
	BF_HTTP_STATUS_CODE_400 = 400,
	BF_HTTP_STATUS_CODE_401 = 401,
	BF_HTTP_STATUS_CODE_402 = 402,
	BF_HTTP_STATUS_CODE_403 = 403,
	BF_HTTP_STATUS_CODE_404 = 404,
	BF_HTTP_STATUS_CODE_405 = 405,
	BF_HTTP_STATUS_CODE_406 = 406,
	BF_HTTP_STATUS_CODE_408 = 408,
	BF_HTTP_STATUS_CODE_409 = 409,
	BF_HTTP_STATUS_CODE_410 = 410,
	BF_HTTP_STATUS_CODE_411 = 411,
	BF_HTTP_STATUS_CODE_412 = 412,
	BF_HTTP_STATUS_CODE_413 = 413,
	BF_HTTP_STATUS_CODE_415 = 415,
	BF_HTTP_STATUS_CODE_416 = 416,
	BF_HTTP_STATUS_CODE_500 = 500,
	BF_HTTP_STATUS_CODE_501 = 501,
	BF_HTTP_STATUS_CODE_502 = 502,
	BF_HTTP_STATUS_CODE_503 = 503,
	BF_HTTP_STATUS_CODE_504 = 504,
	BF_HTTP_STATUS_CODE_507 = 507
};

#endif

